import { shallowMount } from "@vue/test-utils";
import { defineComponent, h } from "vue";
const HelloWorld = defineComponent({
  name: "HelloWorld",
  props: {
    msg: {
      type: String,
    },
  },
  setup(props) {
    return () => {
      return h("div", props.msg);
    };
  },
});
beforeEach(() => {
  console.log("before each");
});

afterEach(() => {
  console.log("after each");
});

beforeAll(() => {
  console.log("before all");
});

afterAll(() => {
  console.log("after all");
});

describe("HelloWorld", () => {
  beforeEach(() => {
    console.log("before each");
  });

  afterEach(() => {
    console.log("after each");
  });

  beforeAll(() => {
    console.log("before all");
  });

  afterAll(() => {
    console.log("after all");
  });
  it("renders props.msg when passed", async () => {
    const msg = "new message";
    const wrapper = shallowMount(HelloWorld, {
      props: { msg },
    });
    /* // 使用异步 方式一  完成后调用done()
    setTimeout(() => {
      expect(wrapper.text()).toMatch("123");
      done();
    }, 100); */
    /*  // 使用异步 方法二  返回peomise  不需要 done了 失败
    return new Promise((resolve) => {
      expect(wrapper.text()).toEqual("123");
      resolve();
    }); */
    // 使用异步 方法三 async await
    await wrapper.setProps({
      msg: "123",
    });
    expect(wrapper.text()).toEqual("123");
  });
  it("should work", () => {
    expect(1 + 1).toBe(2);
  });
});
/* 
test("renders props.msg when passed", () => {
  const msg = "new message";
  const wrapper = shallowMount(HelloWorld, {
    props: { msg },
  });
  expect(wrapper.text()).toMatch(msg);
}); */
